<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>echarts</title>
    <style>
      .chart1,
      .chart2,
      .chart3 {
        width: 800px;
        height: 400px;
      }
    </style>
  </head>
  <body>
    <div class="chart1"></div>
    <div class="chart2"></div>
    <div class="chart3"></div>
    <script src="./echarts.min.js"></script>
    <script>
      const myEcharts1 = echarts.init(document.querySelector(".chart1"));
      const myEcharts2 = echarts.init(document.querySelector(".chart2"));
      const myEcharts3 = echarts.init(document.querySelector(".chart3"));

      // 获取随机的值
      function getRandomValues() {
        const values = [];

        for (let index = 0; index < 7; index++) {
          values.push(Math.round(Math.random() * 100 + 50));
        }

        return values;
      }

      const option1 = {
        xAxis: {
          data: [
            "星期一",
            "星期二",
            "星期三",
            "星期四",
            "星期五",
            "星期六",
            "星期天",
          ],
        },
        yAxis: {},
        series: {
          type: "bar",
          data: getRandomValues(),
        },
      };
      const option2 = {
        xAxis: {
          data: [
            "星期一",
            "星期二",
            "星期三",
            "星期四",
            "星期五",
            "星期六",
            "星期天",
          ],
        },
        yAxis: {},
        series: {
          type: "line",
          data: getRandomValues(),
        },
      };
      const option3 = {
        series: {
          // 饼状图不需要坐标轴
          type: "pie",
          data: [
            {
              name: "xxx",
              value: 111,
            },
            {
              name: "yyy",
              value: 222,
            },
            {
              name: "zzz",
              value: 333,
            },
          ],
          radius: "20%",
        },
      };

      myEcharts1.setOption(option1);
      myEcharts2.setOption(option2);
      myEcharts3.setOption(option3);
    </script>
  </body>
</html>
